﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Shop.Infrastructure.Configuration;

namespace Shop.Infrastructure.Containers
{
    public class Container
    {
        static Container()
        {
            if (Singleton<IUnityContainer>.Instance == null)
            {
                Singleton<IUnityContainer>.Instance = new UnityContainer();
            }
            if (Singleton<Config>.Instance == null)
            {
                Singleton<Config>.Instance = new Config();
            }
        }

        public static IUnityContainer Current
        {
            get
            {
                return Singleton<IUnityContainer>.Instance;
            }
        }

        public static Config ShopConfig
        {
            get
            {
                return Singleton<Config>.Instance;
            }
        }

        public static void Add(IDependencyRegistrar registrar)
        {
            Type t = registrar.GetType();
            if (Current.Resolve(t,t.FullName) == null)
            {
                registrar.Register();
                return;
            }
            Current.RegisterInstance(t.FullName, registrar);

        }
    }
}
